package cn.com.tom.dao.impl;

import cn.com.tom.bean.Education;
import cn.com.tom.dao.EducationDao;
import cn.com.tom.util.Dbs;
import org.springframework.jdbc.core.BeanPropertyRowMapper;

import java.util.ArrayList;
import java.util.List;

public class EducationDaoImpl extends BaseDaoImpl<Education> implements EducationDao {

    @Override
    public boolean save(Education bean) {
        Integer id = bean.id;
        String sql = "";
        List<Object> args = new ArrayList<>();
        args.add(bean.name);
        args.add(bean.type);
        args.add(bean.intro);
        args.add(bean.beginDay);
        args.add(bean.endDay);
        if (id == null || id < 1) {
            sql = "INSERT INTO education(name,type,intro,begin_day,end_day) VALUES(?,?,?,?,?)";
        } else {
            sql = "UPDATE education SET name=?,type=?,intro=?,begin_day=?,end_day=? WHERE id=?";
            args.add(id);
        }
        return Dbs.save(sql, args.toArray());
    }

    @Override
    public Education get(Integer id) {
        return null;
    }

    @Override
    public List<Education> list() {
        String sql = "SELECT id,created_time,name,type,intro,begin_day,end_day FROM education";
        return Dbs.list(sql, new BeanPropertyRowMapper<>(Education.class));
    }

}
